<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<link href="css/redmond/jquery-ui-1.10.3.custom.min.css" rel="stylesheet" type="text/css">	<!-- jquery UI CSS -->
<link href="css/selfTemplate.css" rel="stylesheet" type="text/css">							<!-- homemade CSS -->

<script src="js/jquery-2.1.0.min.js" type="text/javascript"></script>						<!-- jquery -->
<script src="js/jquery-ui-1.10.3.custom.js" type="text/javascript"></script>				<!-- jquery UI -->
<script src="js/jquery.cookie.js" type="text/javascript"></script>							<!-- cookie -->
<script src="js/widgets.js" type="text/javascript"></script>								<!-- homemade js -->

<style type="text/css">
	div#mainDiv {
		width:100%;
		padding-top:20px;
		padding-buttom:20px; 
		padding-right:20px;
		padding-left:15px; 
	}
	td.squadId {
		background-color: #9BC2E6;
	}
	td.bottom {
		border-bottom:1px solid black;
	} 
</style>

<script type="text/javascript">

//取得Jboss回傳的值，寫入 textarea中
function keepMessage(obj) {
	$("#msgBoard").val();
	var tmp = $(obj).attr("msg");
	$("#msgBoard").val(tmp);
}

//將顯示的數字加入千分位
function formatNumber(n) {
    n += "";
    var arr = n.split(".");
    var re = /(\d{1,3})(?=(\d{3})+$)/g;
    return arr[0].replace(re,"$1,") + (arr.length == 2 ? "."+arr[1] : "");
}

$(document).ready(function(){
	
	init("QDH4fOrder.html");
	
	$("#msgBoard").val(null);
	$("#msgBoard").attr("readonly",true);	//先將textArea設成 僅可讀
	
	$("#btnSubmit").bind("click", function(){
		clearErrorMsg();
	 	windowFreeze();
		$.ajax({ type:'post',url:"QDR4Paris",dataType:'json',async:false,
			data: {localSystemId:$.cookie("localSystemId")},
			success : function(reses) {
				if ( reses.length > 0 ) {
					$("#queResRoot").html("<table id='tableQueryDepParis'><thead class='tableFirst'><tr><td colspan='15' class='right'><a href='GenQueryParisReport?localSystemId="+$.cookie("localSystemId")+"' class='fileDownloadPromise zhTwN'>下載查詢結果</a></td></tr><tr><th>上線序號</th><th>交付序號</th><th>緊急上線</th><th>部署環境</th><th>執行帳號</th><th>執行時間</th><th>相關需求</th><th colspan='8'>&nbsp;</th></tr><tbody id='tbodyQueryDepParis'></tbody></table>");
					
					var preSN = 0;
					
					$.each(reses, function(i,res) {

						var req = "";
						$.each(res["reqs"], function(q,rq) {
							req += "<li class='zhTwN'>"+rq.reqSID+"-"+rq.reqDesc+"</li>";
						});
						var tmp = "";
						
						//暫時
						
						var sqID = "";
						if( res["sps"][0] != undefined ) {
							sqID = res["sps"][0].SquadId;
						}
						
						//這時是單頭的部份 
						tmp = "<tr bgcolor='white'><td rowspan="+res.rowspan+" class='int bottom'>"+res.depmainSN+"</td><td rowspan="+res.rowspan+" class='int bottom'>"+res.deliverySN+"</td><td rowspan="+res.rowspan+" class='zhTwN center bottom'>"+(res.isUrgent?"是":"否")+"</td><td rowspan="+res.rowspan+" class='zhTwN center bottom'>"+res.envName+"("+res.envId+")</td><td rowspan="+res.rowspan+" class='zhTwN bottom'>"+res.empName+"</td><td rowspan="+res.rowspan+" class='engN bottom'>"+res.bDT+"</td><td rowspan="+res.rowspan+" class='bottom'><ul>"+req+"</ul></td><td class='engN left squadId'>"+sqID+"</td><td colspan=7>&nbsp;</td></tr>";
						$("#tbodyQueryDepParis").append(tmp);
						
						$.each(res["sps"], function(j,sp) {
							if( j !=0 ) {
								tmp = "<tr bgcolor='white'><td class='engN left squadId'>"+sp.SquadId+"</td><td colspan=7>&nbsp;</td></tr><tr bgcolor='#DDEBF7'><td class='engN right'>a.</td><td class='zhTwN left' colspan=7>關閉 HTTPD 服務</td></tr>";
							} else {
								tmp = "<tr bgcolor='#DDEBF7'><td class='engN right'>a.</td><td class='zhTwN left' colspan=7>關閉 HTTPD 服務</td></tr>";
							}
							$("#tbodyQueryDepParis").append(tmp);
							
							$.each(sp.hts, function(k,ht) {
								var titleResult = "";	//執行結果是否顯示
								if ( ht.s2 != undefined ) { titleResult = "msg='"+rep(ht.s4)+"' title='"+rep(ht.s4)+"'"; }
								tmp = "<tr bgcolor='white'><td>&nbsp;</td><td class='engN'>"+(k+1)+".&nbsp;"+ht.s1+"</td><td colspan=3>&nbsp;</td><td colspan=3 ondblclick='keepMessage(this)' "+titleResult+" class='zhTwN center'>"+(ht.s2==undefined?"未執行":ht.s2)+"</td></tr>";
								$("#tbodyQueryDepParis").append(tmp);	
							});
							$("#tbodyQueryDepParis").append("<tr bgcolor='#DDEBF7'><td class='engN right'>b.</td><td class='zhTwN left'>檔案部署</td><td class='zhTwN center'>版次</td><td class='zhTwN center'>檔案大小(bytes)</td><td>&nbsp;</td><td class='zhTwN center'>開始時間</td><td class='zhTwN center'>結束時間</td><td class='zhTwN center'>結果</td></tr>");
							
							$.each(sp.files, function(m,file) {
								var titleResult = "";	//執行結果是否顯示
								if ( file["depRes"].s3 != undefined ) { titleResult = "msg='"+rep(file["depRes"].s3) +"' title='"+rep(file["depRes"].s3)+"'"; }
								tmp = "<tr bgcolor='white'><td rowspan=2>&nbsp;</td><td class='engN left' rowspan=2>"+(m+1)+".&nbsp;"+file.fileName+"</td><td class='int' rowspan=2>"+file.localVer+"</td><td class='int' rowspan=2>"+formatNumber(file.fileSize)+"</td><td class='zhTwN center'>下線</td><td class='engN'>"+rep(file["depRes"].s5)+"</td><td class='engN'>"+rep(file["depRes"].s7)+"</td><td	ondblclick='keepMessage(this)' "+titleResult+" class='zhTwN center'>"+file["depRes"].s1+"</td></tr>";
								$("#tbodyQueryDepParis").append(tmp);
								titleResult = "";	//執行結果是否顯示
								if ( file["depRes"].s4 != undefined ) { titleResult = "msg='"+rep(file["depRes"].s4) +"' title='"+rep(file["depRes"].s4)+"'"; }
								tmp = "<tr bgcolor='white'><td class='zhTwN center'>部署</td><td class='engN'>"+rep(file["depRes"].s6)+"</td><td class='engN'>"+rep(file["depRes"].s8)+"</td><td ondblclick='keepMessage(this)' "+titleResult+" class='zhTwN center'>"+file["depRes"].s2+"</td></tr>";
								$("#tbodyQueryDepParis").append(tmp);
							});
							 
							tmp = "<tr bgcolor='#DDEBF7'><td class='engN right'>c.</td><td class='zhTwN left' colspan=3>重啟相關檔案</td><td>&nbsp;</td><td class='zhTwN center'>開始時間</td><td class='zhTwN center'>結束時間</td><td class='zhTwN center'>結果</td></tr>";		
							$("#tbodyQueryDepParis").append(tmp);
							$.each(sp.reloadFiles, function(m,file) {
								var titleResult = "";	//執行結果是否顯示
								if ( file["depRes"].s3 != "" ) {
									titleResult = "msg='"+rep(file["depRes"].s3) +"' title='"+rep(file["depRes"].s3)+"'";
									tmp = "<tr bgcolor='white'><td rowspan=2>&nbsp;</td><td class='engN left' colspan=3 rowspan=2>"+Math.round((m+1)/2)+".&nbsp;"+file.fileName+"</td><td class='zhTwN center'>下線</td><td class='engN'>"+rep(file["depRes"].s5)+"</td><td class='engN'>"+rep(file["depRes"].s7)+"</td><td	ondblclick='keepMessage(this)' "+titleResult+" class='zhTwN center'>"+file["depRes"].s1+"</td></tr>";
								} else {
									titleResult = "msg='"+rep(file["depRes"].s4) +"' title='"+rep(file["depRes"].s4)+"'";
									tmp = "<tr bgcolor='white'><td class='zhTwN center'>部署</td><td class='engN'>"+rep(file["depRes"].s6)+"</td><td class='engN'>"+rep(file["depRes"].s8)+"</td><td ondblclick='keepMessage(this)' "+titleResult+" class='zhTwN center'>"+file["depRes"].s2+"</td></tr>";
								}
								$("#tbodyQueryDepParis").append(tmp);
							});
							
							tmp = "<tr bgcolor='#DDEBF7'><td class='engN right'>d.</td><td class='zhTwN left' colspan=7>開啟 HTTPD 服務</td></tr>";		
							$("#tbodyQueryDepParis").append(tmp);
							var hostNumber = $(sp.hts).size();
							
							$.each(sp.hts, function(n,ht) {
								var titleResult = "";	//執行結果是否顯示
								var bottom ="";	//是否產生下劃線
								if( hostNumber == (n+1) ) {
									bottom = " bottom";
								}
								
								if ( ht.s3 != undefined ) { titleResult = "msg='"+rep(ht.s5)+"' title='"+rep(ht.s5)+"'"; }
								tmp = "<tr bgcolor='white'><td class='engN"+bottom+"'>&nbsp;</td><td class='engN"+bottom+"'>"+(n+1)+".&nbsp;"+ht.s1+"</td><td class='engN"+bottom+"' colspan=3>&nbsp;</td><td colspan=3 ondblclick='keepMessage(this)' "+titleResult+" class='zhTwN center"+bottom+"''>"+(ht.s3==undefined?"未執行":ht.s3)+"</td></tr>";
								$("#tbodyQueryDepParis").append(tmp);	
							});
							$("#tbodyQueryDepParis").tooltip();
						});
					});
					
					
				} else {
					$("#queResRoot").html("");
					$("#errShortMsg").html("沒有查詢到結果");
				}
			}, error : function(xhr, ajaxOptions, thrownError) { errorAjx(xhr); }
		});
		
 		windowUnfreeze();
	});
	
	$("button").button();
});

</script>
</head>
<body>
	<div id="header"></div>		<!-- 畫面抬頭 -->

	
	<div id="mainDiv" >
		
		<table id="tableQueryCriDepMemphis">
			<thead class="tableFirst">
				<tr><td class="left" colspan="2"><button id="btnSubmit" type="button">送出</button></td></tr>
				<tr><td colspan="2">&nbsp;</td></tr>
				
				<tr><td class="zhTwN left" colspan="2">JBoss 回傳訊息：</td></tr>
				<tr><td colspan="2"><textarea id="msgBoard" rows="3" cols="100" ></textarea></td></tr>
				<tr><td colspan="2">&nbsp;</td></tr>
			</thead>
		</table>
		<p>
		<div id="queResRoot"></div>
	</div>
	
</body>
</html>